<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!--字体图标-->
    <link href="../../javaex/pc/css/icomoon.css" rel="stylesheet" />
    <!--动画-->
    <link href="../../javaex/pc/css/animate.css" rel="stylesheet" />
    <!--骨架样式-->
    <link href="../../javaex/pc/css/common.css" rel="stylesheet" />
    <!--皮肤（缇娜）-->
    <link href="../../javaex/pc/css/skin/tina.css" rel="stylesheet" />
    <!--jquery，不可修改版本-->
    <script src="../../javaex/pc/lib/jquery-1.7.2.min.js"></script>
    <!--全局动态修改-->
    <script src="../../javaex/pc/js/common.js"></script>
    <!--核心组件-->
    <script src="../../javaex/pc/js/javaex.min.js"></script>
    <!--表单验证-->
    <script src="../../javaex/pc/js/javaex-formVerify.js"></script>
    <title>Title</title>
</head>
<body>

<!--正文内容-->
<div class="main">
    <form id="form">
        <!--文本框-->
        <div class="unit clear">
            <div class="left"><span class="required">*</span><p class="subtitle">编辑内容</p></div>
            <div class="right">
                <input type="text" class="text" id="text" name="text"/>
            </div>
        </div>

        <br>

        <!--提交按钮-->
        <div class="unit clear" style="width: 800px;">
            <div style="text-align: center;">
                <!--表单提交时，必须是input元素，并指定type类型为button，否则ajax提交时，会返回error回调函数-->
                <input type="button" id="send"  value="发送" />
            </div>
        </div>
    </form>
</div>

</body>
<script>
    // 监听点击保存按钮事件
    $("#send").click(function() {
        var id = getQueryVariable("id");
        $.get("/user/detail",{"id": id}, function(data){
        // 表单验证函数
            var user = data.data;
        var text = $("#text").val();
        var email = user.email;
        var username = user.username;
        var json = {"username":username,"email":email,"text":text};
        $.ajax({
            //请求方式
            type : "POST",
            //请求的媒体类型
            contentType: "application/json;charset=UTF-8",
            //请求地址
            url : "/user/send",
            //数据，json字符串
            data : JSON.stringify(json),
            //请求成功
            success : function(result) {
                console.log(result);
                // 获取集合属性
                var data = result.data;
                var code = result.code;

                if (code == 200) {
                    javaex.message({
                        content : "发送成功",
                        type : "success"
                    });

                    // 跳转至列表
                    setTimeout(function(){window.location.href="/reader/reader-list";},1500)
                }

            },
            //请求失败，包含具体的错误信息
            error : function(e){
                console.log(e.status);
                console.log(e.responseText);
            }
        });
    });
    });

    // 获取地址栏参数
    function getQueryVariable(variable){
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return false;
    }
</script>
</html>